export const state = () => ({
    user: null
});

export const mutations = {
    SET_USER(state, user) {
        state.user = user;
    }
};

export const actions = {
    nuxtServerInit({ commit }, { req, route, app, store }) {
        if (req.session) {
            // 有session
            if (req.session.user) {
                // 用户登录
                console.log(req.session);
                const user = req.session.user;
                commit('SET_USER', user);
            }
        }
    },

    login({ commit }, context) {
        commit('SET_USER', context);
    }
};
